package web.fabrimind.sm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.bdm.domain.ProductionLine;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.sm.domain.ShiftSchedule;
import web.fabrimind.sm.service.IShiftScheduleService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 班次排班Controller
 * 
 * @author zhihui
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/sm/schedule")
public class ShiftScheduleController extends BaseController
{
    @Autowired
    private IShiftScheduleService shiftScheduleService;

    /**
     * 查询班次排班列表
     */
    @PreAuthorize("@ss.hasPermi('sm:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShiftSchedule shiftSchedule)
    {
        startPage();
        List<ShiftSchedule> list = shiftScheduleService.selectShiftScheduleList(shiftSchedule);
        return getDataTable(list);
    }

    /**
     * 导出班次排班列表
     */
    @PreAuthorize("@ss.hasPermi('sm:schedule:export')")
    @Log(title = "班次排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShiftSchedule shiftSchedule)
    {
        List<ShiftSchedule> list = shiftScheduleService.selectShiftScheduleList(shiftSchedule);
        ExcelUtil<ShiftSchedule> util = new ExcelUtil<ShiftSchedule>(ShiftSchedule.class);
        util.exportExcel(response, list, "班次排班数据");
    }

    /**
     * 获取班次排班详细信息
     */
    @PreAuthorize("@ss.hasPermi('sm:schedule:query')")
    @GetMapping(value = "/{scheduleId}")
    public AjaxResult getInfo(@PathVariable("scheduleId") Long scheduleId)
    {
        return success(shiftScheduleService.selectShiftScheduleByScheduleId(scheduleId));
    }

    /**
     * 新增班次排班
     */
    @PreAuthorize("@ss.hasPermi('sm:schedule:add')")
    @Log(title = "班次排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShiftSchedule shiftSchedule)
    {
        return toAjax(shiftScheduleService.insertShiftSchedule(shiftSchedule));
    }

    /**
     * 修改班次排班
     */
    @PreAuthorize("@ss.hasPermi('sm:schedule:edit')")
    @Log(title = "班次排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShiftSchedule shiftSchedule)
    {
        return toAjax(shiftScheduleService.updateShiftSchedule(shiftSchedule));
    }

    /**
     * 删除班次排班
     */
    @PreAuthorize("@ss.hasPermi('sm:schedule:remove')")
    @Log(title = "班次排班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scheduleIds}")
    public AjaxResult remove(@PathVariable Long[] scheduleIds)
    {
        return toAjax(shiftScheduleService.deleteShiftScheduleByScheduleIds(scheduleIds));
    }

    /**
     * 查询所属团队名称列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('sm:shift:list')")
    @GetMapping("/shift/getlist")
    public AjaxResult getShiftList(ShiftSchedule shiftSchedule) {
        List<ShiftSchedule> shiftList = shiftScheduleService.selectShiftList(shiftSchedule);
        return AjaxResult.success(shiftList);
    }


}
